package com.chhuang.huaao.thread;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import com.chhuang.huaao.po.HaMachine;
import com.chhuang.utils.Assert;

/**
 * 获取一组设备的状态
 * @author CHHUANG
 *
 */
public class MachineFlushTask implements Runnable {
	
	private List<HaMachine> machines;
	
	public MachineFlushTask(List<HaMachine> machines){
		this.machines = machines;
	}
	
	private static ExecutorService pool;
	
	@Override
	public void run() {
		if(Assert.isInvalidCollection(machines)){
			return;
		}
		if(pool!=null){
			pool.shutdownNow();
		}
		pool = Executors.newFixedThreadPool(3);
		for(HaMachine machine : machines){
			if(machine.getMachineOnlineStatus()!=null && machine.getMachineOnlineStatus()==1){
				pool.execute(new MachineStatusFlushThread(machine));//发送需要获取设备信息的命令
			}
		}
		pool.shutdown();
	}

}
